<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%setting}}`.
 */
class m230918_075020_create_setting_table extends Migration
{
    const TABLE_NAME = '{{%setting}}';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=MyISAM COMMENT="系统设置表格"';
        }

        $this->createTable(self::TABLE_NAME, [
            'code' => $this->string(50)->notNull()->comment('标识码'),
            'value' => $this->text()->comment('值'),
            'name' => $this->string()->notNull()->defaultValue('')->comment('名称'),
            'group' => $this->string(50)->notNull()->comment('分组'),
            'created_at' => $this->dateTime()->notNull()->comment('创建时间'),
            'updated_at' => $this->dateTime()->defaultValue(null)->comment('上次更新'),
        ], $tableOptions);

        $this->addPrimaryKey('key_code', self::TABLE_NAME, 'code');
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable(self::TABLE_NAME);
    }
}
